class Solution {

    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

        ListNode p1 = list1;

        ListNode p2 = list2;

        ListNode newL = new ListNode();

        ListNode cur = newL;


        while (p1 != null && p2 != null) {

            if (p1.val > p2.val) {

                newL.next = p2;

                p2 = p2.next;

            } else {

                newL.next = p1;

                p1 = p1.next;

            }

            newL = newL.next;

        }

        if (p1 == null) {

            newL.next = p2;

        }

        if (p2 == null) {

            newL.next = p1;

        }

        return cur.next;

    }
}